package com.bml.architect.consumer.web;

import org.apache.dubbo.rpc.RpcContext;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@Component
public class MyConsumerIntercept implements HandlerInterceptor {

    private  List<String> cards = new ArrayList<>();
    @PostConstruct
    public void init(){
        cards.add("6213518888888");
        cards.add("6213516666666");
    }



    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String card = request.getParameter("cardNo");
        System.out.println("++++"+card);
        if(cards.contains(card)){
            RpcContext.getContext().setAttachment("dubbo.tag","aaa");
        }else{
            RpcContext.getContext().setAttachment("dubbo.tag","bbb");

        }
        return true;
    }
}
